package com.heitian.ssm.utils;

/**
 * Created with IntelliJ IDEA.
 * User: mishuai
 * Date: 2018-04-23
 * Time: 19:04
 * Des:
 */
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;


public class Write {
    public static void writeContent() throws IOException {
        System.out.println("写入文件开始--------");
        String name="张三";
// 创建文件
        File file=new File("D:\\"+name+".txt");
// 判断文件否存在
        if (!file.isDirectory()) {
            file.createNewFile();
        }else {
            System.out.println("文件已存在");
        }
// 创建输出流FileOutputStream对象out
        FileOutputStream out=new FileOutputStream(file);

// 创建stringbuffer对象，进行字符串拼接
            StringBuffer sb=new StringBuffer();
// 写入文件
            sb.append("dfaewfhoiaewhfoaiewjfioeawjoijaewoij  fjaeiwofjaewio              fjieawjfoiewajf");
// 选择utf-8的编码形式写入
            out.write(sb.toString().getBytes("UTF-8"));

// 关闭输出流
        out.close();
    }
}